package com.controller.selling 
{	
	import com.model.valueObjects.VoTransactionNote;
	import com.service.TransactionNote;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class SellingTransactionNoteController extends AbstractController
	{
	
		[Inject]
		public var transactionNoteDetails:TransactionNote;
		
		public function SellingTransactionNoteController()
		{
			super();
		}
		
		[EventHandler(event="SellingTransactionNoteEvent.GET_ALL")]
		public function getAll():void{
			sh.executeServiceCall(transactionNoteDetails.getAllSalesNotes(),getAllResult, handleFault );
		}
		private function getAllResult(event:ResultEvent):void
		{
			if(model.currentMenu=='crDbSellingBtn')
				model.currentSellTableIndex=5;
			
			model.sellingTransactionNote=event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SellingTransactionNoteEvent.ADD", properties="sellingTransactionNoteVo")]
		public function add(sellingTransactionNoteVo:VoTransactionNote):void
		{
			sh.executeServiceCall(transactionNoteDetails.addNote(sellingTransactionNoteVo), addResult, handleFault );	
		}
		
		private function addResult(event:ResultEvent):void
		{
			if(model.saveCloseBtn)model.currentSellFormsIndex=0;	
			Alert.show( "Transaction Note added" );
			
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
			getAll();
		}
		
		
		private function handleFault(event:FaultEvent):void
		{
			Alert.show( event.fault.faultDetail, "Error" );
		}
	}
}